function random(min, max) {
	return Math.floor(min + Math.random() * (max - min));
}

//float comparation
function num_f(a) {
	a = parseFloat(a);
	if (isNaN(a)) return 0;

	var PRECISION = 2;
	var dec = Math.pow(10, PRECISION);
	return Math.round(a * dec) / dec;
}

function cmp_f(a, op, b) {
	eval('r = num_f(' + a + '-' + b + ')' + op + '0');
	return r;
}

//object copy
function obj_cpy(a) {
	if (arguments.lenght < 1)
		return {};

	var obj;
	if (typeof(a) === 'object') {
		obj = (a.constructor === Array) ? [] : {};
		for (var i = 0; i < arguments.length; i++) {
			var dist_obj = arguments[i];
			for (var name in dist_obj) {
				if (dist_obj.hasOwnProperty(name)) {
					if (typeof(dist_obj[name]) === 'object')
						obj[name] = obj_cpy(dist_obj[name]);
					else
						obj[name] = dist_obj[name];
				}
			}
		}
	} else
		obj = a;

	return obj;
};

function in_array(value, array) {
	var i = array.length;
	while (i--) {
		if (array[i] === value)
			return true;
	}
	return false;
}

function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]);
	return null;
}

/**
 * 设置cookie
 * @param cookieName
 * @param cookieValue
 * @param seconds 过期时间
 * @param path 路径
 * @param domain 域
 */
function setCookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds);
	document.cookie = cookieName + '=' + escape(cookieValue) + (seconds ? '; expires=' + expires.toGMTString() : '') + (path ? '; path=' + path : '/') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : '');
}

function getsec(str) {
	var str1 = str.substring(1, str.length) * 1;
	var str2 = str.substring(0, 1);
	if (str2 == "s") {
		return str1 * 1000;
	} else if (str2 == "h") {
		return str1 * 60 * 60 * 1000;
	} else if (str2 == "d") {
		return str1 * 24 * 60 * 60 * 1000;
	}
}

function getCookie(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

	if (arr = document.cookie.match(reg))

		return (arr[2]);
	else
		return "";
}

function delCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie(name);
	if (cval != null)
		document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

//获取域名
function getHost(url) {
	var host = "null";
	if (typeof url == "undefined" || null == url) url = window.location.href;
	var regex = /.*\:\/\/([^\/|:]*).*/;
	var match = url.match(regex);
	if (typeof match != "undefined" && null != match) host = match[1];
	if (typeof host != "undefined" && null != host) {
		var strAry = host.split(".");
		if (strAry.length > 1) host = strAry[strAry.length - 2] + "." + strAry[strAry.length - 1];
	}
	return host;
}

function iScrollClick() {
	if (/iPhone|iPad|iPod|Macintosh/i.test(navigator.userAgent)) return true;
	if (/Chrome/i.test(navigator.userAgent)) return (/Android/i.test(navigator.userAgent));
	if (/Silk/i.test(navigator.userAgent)) return false;
	if (/Android/i.test(navigator.userAgent)) {
		var s = navigator.userAgent.substr(navigator.userAgent.indexOf('Android') + 8, 3);
		return parseFloat(s[0] + s[2]) < 44 ? false : true
	}
}

function isApple() {
	if (/iPhone|iPad|iPod|Macintosh/i.test(navigator.userAgent)) return true;
	return false;
}

function judgeAndroidVersion() {
	if (/Android/i.test(navigator.userAgent)) {
		var s = navigator.userAgent.substr(navigator.userAgent.indexOf('Android') + 8, 3);
		return parseFloat(s);
	}
}

function validate_mobile(mobile) {
	if (/^1[3458]\d{9}$/.test(mobile)) return true;
	return false;
}

function validate_pwd(pwd) {
	if (/^\w{6,}$/.test(pwd)) return true;
	return false;
}

function validate_sms_code(sms_code) {
	if (/^\d{6}$/.test(sms_code)) return true;
	return false;
}

function count(o) {
	var t = typeof o;
	if (t == 'string') {
		return o.length;
	} else if (t == 'object') {
		var n = 0;
		for (var i in o) {
			n++;
		}
		return n;
	}
	return false;
}

function isWeiXin() {
	var ua = window.navigator.userAgent.toLowerCase();
	if (ua.match(/MicroMessenger/i) == 'micromessenger') {
		return true;
	} else {
		return false;
	}
}

function isUrl(str) {
	if (/http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/.test(str)) return true;
	return false;
}

//need be Y-m-d h:i:s
function parseDateString(str) {
	var p = str.split(' ');

	var y = p[0].split('-')[0];
	var m = p[0].split('-')[1] - 1;
	var d = p[0].split('-')[2];
	if (p.length < 1) {
		return new Date(y, m, d);
	}
	var h = p[1].split(':')[0];
	var i = p[1].split(':')[1];
	var s = p[1].split(':')[2];
	return new Date(y, m, d, h, i, s);
}

function fix2datenum(num) {
	if (parseInt(num) < 10)
		return '0' + num;
	return num;
}

$(function () {
	//获取用户唯一信息 by andfly 20151030
	document.body.parentNode.style.fontSize = parseInt(document.body.clientWidth) / 20 + 'px';
	var stati_unique_id = getCookie('stati_client_mark_code');
	if (stati_unique_id) {
	} else {
		stati_unique_id = new Date().getTime() + parseInt(Math.random() * 1000);
		setCookie('stati_client_mark_code', stati_unique_id, 365 * 24 * 3600 * 1000, '/', '.' + getHost(window.location.href));
	}
});
